package org.langqiao.appproject.时钟新;

import java.awt.Color;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class ClockPanel extends JPanel{
	JLabel timeLabel;
	 private int lastxs, lastys, lastxm, lastym, lastxh, lastyh;
	public ClockPanel(){
		super();
		setSize(400,400);
		setLayout(null);
		lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
		
	}
	public void paint(Graphics g){
		int xcenter=150;
		int ycenter=150;
		super.paint(g);
		g.drawOval(0, 0, 300, 300);
		g.drawString("12", 150, 15);
		g.drawString("3", 290, 150);
		g.drawString("6", 150, 295);
		g.drawString("9", 5, 150);
		Date date=new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("EE MM月 dd号  HH:mm:ss yyyy年");
		g.drawString(formatter.format(date), 100, 350);
		
		 int xh, yh, xm, ym, xs, ys;
		SimpleDateFormat form = new SimpleDateFormat();
		form.applyPattern("HH");
		int h=Integer.parseInt(form.format(date));
		form.applyPattern("mm");
		int m=Integer.parseInt(form.format(date));
		form.applyPattern("ss");
		int s=Integer.parseInt(form.format(date));
		 xs = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 145 + xcenter);
		  ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 145 + ycenter);
		  xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 130 + xcenter);
		  ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 130 + ycenter);
		  xh = (int) (Math.cos((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 100 + xcenter);
		  yh = (int) (Math.sin((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 100 + ycenter);
		  	  g.setColor(Color.red);
			  g.drawLine(xcenter, ycenter, xs, ys);
			  g.setColor(Color.blue);
			  g.drawLine(xcenter, ycenter - 1, xm, ym);
			  g.drawLine(xcenter - 1, ycenter, xm, ym);
			  g.setColor(Color.black);
			  g.drawLine(xcenter, ycenter - 1, xh, yh);
			  g.drawLine(xcenter - 1, ycenter, xh, yh);
	}
	
	public void update(Graphics g) {
		
	}
}
